<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: categories_left.php 502 2014-01-31 15:50:06Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 502 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-31 15:50:06 +0000 (Fri, 31 Jan 2014) $
*
* 	http://www.edv-mueller.com
*
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$box_smarty = new Smarty();

$path_parts = pathinfo(__FILE__); 
$box_name = $path_parts['filename'];

define('CATEGORY_ONLINESHOP', 0);

include_once(DIR_FS_INC.'inc.get_categories.php');
//echo_e($_REQUEST); echo_e($_GET); echo_e($_POST);
function _getNaviPath($level, $arr_cPath, $categories, $flat=true) {
  $items = array();

  if (count($arr_cPath) < $level) return $items;
  
  //echo_e('- childs [' . $level . ']', 'N'); echo_e($categories);
  foreach($categories as $category) {
    $_category = $category;
    $_category['children_count'] = $_category['children']['count'];
    $_category['active'] = false;
    unset($_category['children']);
    $items[] = $_category;
    
    if ($arr_cPath[$level] == $category['cat_id']) {
      $items[count($items)-1]['active'] = true;
    
      if ($_category['children_count'] > 0) {
        //echo_e('get childs [' . $level . ']'. $arr_cPath[$level]);
        if ($flat)
          $items = array_merge($items, _getNaviPath($level+1, $arr_cPath, $category['children']['items'], $flat));
        else
          $items[count($items)-1]['children_items'] = _getNaviPath($level+1, $arr_cPath, $category['children']['items'], $flat);
      }
    }
  }
  return $items;
}

if (!CacheCheck() && !FORCE_CACHE) {
	$cache = false;
	$box_smarty->caching = false;

} else {
	$cache = true;
	$box_smarty->caching = true;
	$box_smarty->cache_lifetime = CACHE_LIFETIME;
	$box_smarty->cache_modified_check = CACHE_CHECK;
	$cache_id = 'box_'.$box_name.'_'.$_SESSION['language'].'_'.$_SESSION['customers_status']['customers_status_id'].'_'.$_GET['cPath'];
}

if(!$box_smarty->isCached(CURRENT_TEMPLATE.'/boxes/box_'.$box_name.'.html', $cache_id) || !$cache){
	require_once(DIR_FS_INC.'inc.count_products_in_category.php');
	
	$cat_config = array(
    'min_level' =>	1,
		'max_level' =>	2,
		'hide_empty' =>	(CATEGORY_HIDE_EMPTY=='true'?true:false));

  $arr_cPath = explode('_', $_GET['cPath']);
  //echo_e($arr_cPath);
  if (is_array($arr_cPath) && count($arr_cPath) >= 1) {
    $cat_start = $arr_cPath[0];
  }
  else
    $cat_start = CATEGORY_ONLINESHOP;
    
  $categories = get_categories($cat_start, 1);
//echo_e($categories);
  
  $BOX_CONTENT = _getNaviPath(1, $arr_cPath, $categories, false);
//echo_e($BOX_CONTENT, 'E');
		
	$box_smarty->assign('box_name', $box_name);
	$box_smarty->assign('language', $_SESSION['language']);
	$box_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
	$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');
	$box_smarty->assign('BOX_CONTENT', $BOX_CONTENT);
}

$get[] = 'cmg=yes';

if(!$cache)
	$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_'.$box_name.'.html');
else
	$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_'.$box_name.'.html', $cache_id);